package nettyProtocol.test;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelPipeline;
import nettyProtocol.pojo.Header;
import nettyProtocol.pojo.NettyMessage;
import nettyProtocol.serverAndClient.NettyClient;

public class Client extends NettyClient {

    @Override
    public void initChannel(ChannelPipeline pipeline) {
        pipeline.addLast(new MessageRespHandler());
    }

    public static void main(String[] args) throws Exception {
        NettyClient client =  new Client();
        client.connect(9000,"127.0.0.1");

        NettyMessage message = new NettyMessage();
        Header header = new Header();
        header.setType((byte)1);
        header.setSessionID(100L);
        message.setHeader(header);
        message.setBody("客户端发送的消息");
        client.sendData(message);

//        client.disConnect();
    }

    private class MessageRespHandler extends ChannelInboundHandlerAdapter {
        @Override
        public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
            System.out.println(msg);
        }
    }
}
